package com.epam.lunch.service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;


import com.epam.lunch.domain.Address;
import com.epam.lunch.domain.Category;
import com.epam.lunch.domain.Food;
import com.epam.lunch.domain.Menu;
import com.epam.lunch.domain.Restaurant;

public class HardCodedRestaurantRepository implements RestaurantRepository {

	private List<Restaurant> restaurants;
	private Map<Long, Food> foodMap = new HashMap<Long, Food>();
	
	public HardCodedRestaurantRepository() {
		restaurants = new ArrayList<Restaurant>();
		
		Menu m1 = new Menu();		
		m1.getFoods().add(new Food(1,"pacal", 670, "light soup", Category.DISHES));
		m1.getFoods().add(new Food(2,"babgulyas", 850, "creates some gas", Category.SOUP));
		m1.getFoods().add(new Food(3, "pangalaktikus gegepukkaszto", 1200, "hard stuff", Category.SHOTS));
		Restaurant r1 = new Restaurant("Ancsa", new Address("Futo utca 80", "budapest", "1082", "hungary"), m1);
		restaurants.add(r1);
		
		Menu m2 = new Menu();
		m2.getFoods().add(new Food(101,"tokfozelek", 500, "i necer liked it", Category.DISHES));
		m2.getFoods().add(new Food(102,"brassoi", 1100, "creates some gas", Category.DISHES));
		m2.getFoods().add(new Food(103,"kola", 300, "no description needed!", Category.SOFT_DRINK));
		m2.getFoods().add(new Food(104,"cekla", 300, "boborjan's favourite", Category.DISHES));
		m2.getFoods().add(new Food(105,"kave", 250, "100% arabica", Category.DISHES));
		m2.getFoods().add(new Food(105,"ceklas kola", 350, "strange taste", Category.DISHES));
		Restaurant r2 = new Restaurant("TenMinutes", new Address("Futo utca 47", "budapest", "1082", "hungary"), m2);
		restaurants.add(r2);
		
		storeAllFoodFromRestaurant(r1);
		storeAllFoodFromRestaurant(r2);
	}
	
	private void storeAllFoodFromRestaurant(Restaurant restaurant) {
		for (Food next : restaurant.getMenu().getFoods()) {
			foodMap.put(next.getId(), next);
		}
	}
	@Override
	public List<Restaurant> getAllRestaurants() {
		return restaurants;
	}
	
	@Override
	public Food findFoodById(long foodId) {
		
		return foodMap.get(new Long(foodId));
	}

}
